package com.hdaccp.foodsales.controller;
import com.hdaccp.foodsales.dao.xiaoshouDao;
import com.hdaccp.foodsales.entity.Jinhuo;
import com.hdaccp.foodsales.entity.Shangpin;
import com.hdaccp.foodsales.entity.Xiaoshou;
import com.hdaccp.foodsales.pojo.jingbanBean;
import com.hdaccp.foodsales.service.jinhuoService;
import com.hdaccp.foodsales.service.xiaoshouService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/xiaoshou")
@Scope("prototype")
public class xiaoshouController {
@Autowired
   private xiaoshouService xiaoshouService;
@Autowired
private xiaoshouDao xiaoshouDao;


    @RequestMapping("/addhuo")
    @ResponseBody
    public int addhuo(Xiaoshou xiaoshou){ return xiaoshouService.addhuo(xiaoshou);}

    @RequestMapping("/updata")
    @ResponseBody
    public int updata(Shangpin shangpin){
        return xiaoshouService.update(shangpin);
    }
    @RequestMapping("/del")
    @ResponseBody
    public int del(Shangpin shangpin){
        return xiaoshouDao.del();
    }

    @RequestMapping("/queryAll")
    @ResponseBody
    public List<Xiaoshou> query(HttpServletRequest request){
        List<Xiaoshou> list = xiaoshouService.queryAll();
        return list;
    }

    @RequestMapping("/query")
    @ResponseBody
    public Map<String,Object> query1(HttpServletRequest request){
        Map<String,Object> map = new HashMap<String,Object>() ;
        map.put("rows",xiaoshouService.query()) ;
        return map;
    }

    @RequestMapping("/queryjingban")
    @ResponseBody
    public Map<String,List<Object>>queryjingban(){
        Map<String,List<Object>> map = new HashMap<>() ;
        List<jingbanBean> list =xiaoshouDao.queryjingban();
        List<Object> list1 =new ArrayList<>();
        List<Object> list2 =new ArrayList<>();
        for (jingbanBean bean :list){
            list1.add(bean.getJingban());
            list2.add(bean.getJingbancount());
        }
        map.put("ren",list1);
        map.put("ren1",list2);
        return map;
    }

}
